package commands;

import java.io.PrintWriter;

import server.AccessDeniedException;
import server.RefrensMonitor;
import server.Subject;

public class AddAction implements Action {

	private PrintWriter pw;
	private Subject sub;
	private String message;

	public AddAction(PrintWriter pw, Subject sub, String string) {
		this.pw = pw;
		this.sub = sub;
		this.message = string;
	}

	@Override
	public void perform() {
		String[] args = message.split(" ");
		if(args.length != 3){
			pw.println("Number of arg invalid");
			return;
		}
		try {
			int a = RefrensMonitor.getInstance().add(sub, args[0], args[1], args[2]);
			pw.println("You new file has number" + " " + a);
		} catch (AccessDeniedException e) {
			pw.println("Access denied");
			e.printStackTrace();
		}
	}

}
